cmake_minimum_required (VERSION 2.8)
project (f_engine)

#----------------------------

IF (NOT CMAKE_BUILD_TYPE)
 SET(CMAKE_BUILD_TYPE "Debug")
# SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE) 

set(GRAPH_ENGINE OGRE_3D)
#----------------------------

set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
find_package(Boost COMPONENTS system thread REQUIRED)

if(${CMAKE_SYSTEM} MATCHES "Windows")
  #win XP minimum
  add_definitions(-D_WIN32_WINNT=0x0501)
else()
endif()

#setup include directories
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/engine)
include_directories(${CMAKE_SOURCE_DIR}/external)
include_directories(${CMAKE_SOURCE_DIR}/external/lua)
include_directories(${CMAKE_SOURCE_DIR}/external/zziplib)
include_directories(${CMAKE_SOURCE_DIR}/external/bullet)
include_directories(${CMAKE_SOURCE_DIR}/external/bullet/src)
include_directories(${CMAKE_SOURCE_DIR}/external/ois/includes)

#setup library directories
link_directories(${Boost_LIBRARY_DIRS})

#setup build variables
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

file(COPY ${CMAKE_SOURCE_DIR}/etc/ DESTINATION ${EXECUTABLE_OUTPUT_PATH} FILES_MATCHING PATTERN *.xml)
file(COPY ${CMAKE_SOURCE_DIR}/media/ DESTINATION ${EXECUTABLE_OUTPUT_PATH} FILES_MATCHING PATTERN *.zip)

#BUILD ALL

#1. external libraries

#physics engine libs that we need
set(BULLET_PHYSICS_ENGINE_LIBS BulletCollision BulletDynamics LinearMath)

add_subdirectory(external)


#2. graphical engine wrapper
if("${GRAPH_ENGINE}" MATCHES "OGRE_3D")

  if(${CMAKE_SYSTEM} MATCHES "Windows")
    #windows build
    
    if (NOT OGRE_ROOT AND NOT $ENV{OGRE_ROOT} STREQUAL "")
      set(OGRE_SDK_DIR $ENV{OGRE_ROOT})
    else()
      message(FATAL_ERROR "OGRE_ROOT environment variable not found")
    endif()
    
    set(OGRE_INCLUDE_DIR ${OGRE_SDK_DIR}/include/OGRE)
    set(OGRE_LIB_DIR ${OGRE_SDK_DIR}/lib/${CMAKE_BUILD_TYPE})
  
    if(${CMAKE_BUILD_TYPE} MATCHES Debug)
      set(OGRE_LIB OgreMain_d)
    else()
      set(OGRE_LIB OgreMain)
    endif()
     
  else()
    #linux build
    set(OGRE_INCLUDE_DIR "/usr/local/include/OGRE")
    set(OGRE_LIB_DIR "/usr/local/lib")
    set(OGRE_LIB OgreMain)
  endif()

  include_directories(${OGRE_INCLUDE_DIR})

  link_directories(${OGRE_LIB_DIR})

  #build ogre wrapper
  add_subdirectory(ogre_render)
  
  set(GRAPH_ENGINE_LIBS ${OGRE_LIB} ogre_render ogre_logger ogre_scene_node)
endif()


#3. engine code
add_subdirectory(engine)

#4. tests
add_subdirectory(tests)

#5. link game
add_executable(main main.cpp)
target_link_libraries(main f_engine ${GRAPH_ENGINE_LIBS} ${BULLET_PHYSICS_ENGINE_LIBS})


